package net.homelinux.chaoswg.io.renga.core.gui.operations.helper;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

public class Connector {
    public enum ConnectorType {
        INPUT, OUTPUT
    }

    final Rectangle area;
    
    final ConnectorType type;

    public Connector (final ConnectorType type) {
        this.area = new Rectangle (new Point (0,0), new Dimension (8,8));
        
        this.type = type;
    }
    
    public Connector(final int x, final int y, final ConnectorType type) {
        this.type = type;

        this.area = new Rectangle (new Point (x, y), new Dimension (8,8));
    }

    public Point getCenter () {
        return new Point (this.area.x + 4, this.area.y + 4);
    }
    
    public void setCenter (final int x, final int y) {
        this.area.x  = x- 4;
        this.area.y = y - 4;
    }

    public ConnectorType getType() {
        return type;
    }

    public void moveBy (final int dx, final int dy) {
        this.area.x += dx;
        this.area.y += dy;
    }
    
    public void drawYourself(final Graphics g) {
        g.setColor(Color.BLACK);
        g.fillOval(this.area.x, this.area.y, 8, 8);

        Color color = Color.WHITE;
        switch (type) {
            case INPUT:
                color = Color.ORANGE;
                break;
            case OUTPUT:
                color = Color.BLUE;
                break;
        }
        g.setColor(color);
        g.fillOval(this.area.x + 1, this.area.y + 1, 6, 6);
        g.setColor(Color.BLACK);
    }

    public boolean contains(final int x, final int y) {
        return contains (new Point (x, y));
    }
    
    public boolean contains (final Point p) {
        return area.contains(p);
    }
}
